#include<bits/stdc++.h>
using namespace std;

struct node {
	int x,y,t;
} q[10000];

int n,m,ans,dx[4]= {-1,1,0,0},dy[4]= {0,0,-1,1};

int max_n,max_m,min_n,min_m;

char f[1005][1005];

void bfs(int x,int y) {
	int h = 0,t = 1,xx,tt,yy;
	q[0].t = 0, q[0].x = x, q[0].y= y,f[x][y] ='*';
	max_n=max(max_n,x);
	max_m=max(max_m,y);
	min_n=min(min_n,x);
	min_m=min(min_m,y);

	while(h != t) {
		for(int i = 0; i < 4; i++) {
			xx = q[h].x + dx[i];
			yy = q[h].y + dy[i];
			tt = q[h].t + 1;
			if(xx < 1 || yy < 1 ||xx > n||yy > m|| f[xx][yy] != '#')   continue;
			f[xx][yy] = '*';
			q[t].x = xx;
			q[t].y = yy;
			q[t].t = tt;
			max_n=max(max_n,xx);
			max_m=max(max_m,yy);
			min_n=min(min_n,xx);
			min_m=min(min_m,yy);
			t =(t+1) % 10000;
		}
		h=(h+1) % 10000;
	}
}

int main() {
	scanf("%d%d",&n,&m);
	for(int i=1; i<=n; i++) {
		for(int j = 1; j <= m; j++) {
			cin >> f[i][j];
		}
	}
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			if(f[i][j] == '#') {
				max_n = max_m = -1;
				min_n = min_m = 1000000;
				bfs(i,j);
				for(int k = min_n; k <= max_n; k++) {
					for(int l =min_m; l <= max_m; l++) {
						if(f[k][l] != '*') {
							printf("Bad placement.");
							return 0;
						}
					}
				}
				ans++;
			}
		}
	}


	printf("There are %d ships.",ans);
	return 0;
}

